<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <!-- 响应式-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.2.4/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">
    <title>博客发布</title>
</head>
<body>
<!--导航-->
<nav th:replace="admin/_fragments :: menu(1)" >
</nav>
<div class="ui attached menu">
    <div class="ui right aligned container">
        <div class="menu right">
            <a th:href="@{/admin/blog/input}" class="item active">发布</a>
            <a th:href="@{/admin/mblog}" class="item ">列表</a>
        </div>
    </div>
</div>
<!--中间部分-->
<div class="m-container-large m-padded-tb-large">
    <div class="ui container">
        <form id="blog-form" th:object="${blog}" th:action="${blog.id == null} ? @{/admin/mblog} : @{/admin/blog/{id}/input(id=${blog.id})}" method="post" class="ui form">
            <input type="hidden" name="published">
            <input type="hidden" name="id" th:value="*{id}">
            <div class="required field">
                <!--input，是用来调整宽度的;labeled⑩字体居中并且加大-->
                <div class="ui labeled  left  input" >
                    <div class="ui selection compact teal basic dropdown label" >
                        <input type="hidden" value="原创" name="flag" th:value="*{flag}" >
                        <i class="dropdown icon"></i>
                        <div class="text">原创</div>
                        <div class="menu">
                            <div class="item" data-value="原创">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <input type="text"  name="title" placeholder="标题" th:value="*{title}">
                </div>
            </div>

            <div class="required field" >
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea placeholder="博客内容" th:text="*{content}" name="content" style="display: none">
                    </textarea>
                </div>
            </div>
            <div class="two fields">
                <div class="required field">
                    <div class="ui left labeled input">
                        <label class="ui label basic teal">分类</label>
                        <div class="ui dropdown search  selection fluid">
                            <input type="hidden" name="type.id" th:value="*{type} != null ? *{type.id}">
                            <i class="dropdown icon"></i>
                            <div class="default text">类型</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" th:data-value="${type.id}"
                                     th:text="${type.name}">开发者手册
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <!--如果想要两个独占一行的块并列在一起，就得给这两个元素外再包一个div块-->
                    <div class="ui right labeled input">
                        <label class="ui label basic teal">标签</label>
                        <div class="ui fluid multiple search selection dropdown">
                            <input type="hidden" name="tagIds" th:value="*{tagIds}">
                            <i class="dropdown icon"></i>
                            <div class="default text">标签</div>
                            <div class="menu">
                                <div class="item" th:data-value="${tag.id}" th:each="tag : ${tags}" th:text="${tag.name}">java</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="required field">
                <div class="ui labeled fluid input">
                    <label class="ui teal basic label">首图</label>
                    <input type="text"   th:value="*{firstPicture}" name="firstPicture" placeholder="首图引用地址">
                </div>
            </div>
            <div class="required field">
                <textarea name="description"  placeholder="博客描述..." maxlength="200" th:text="*{description}"></textarea>
            </div>
            <!--inline消除外边距将fields这个div贴到上层块中-->
            <div class="inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" th:checked="*{recommend}" name="recommend" id="recommend" class="hidden">
                        <label for="recommend" >推荐</label>
                    </div>
                </div>
                <div class="inline field">
                    <div class="ui checkbox">
                        <input type="checkbox" th:checked="*{shareStatement}" name="shareStatement" id="shareStatement" class="hidden">
                        <label for="shareStatement">转载声明</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" th:checked="*{appreciation}" name="appreciation" id="appreciation" class="hidden">
                        <label for="appreciation">赞赏</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" th:checked="*{commentabled}" name="commentabled" id="commentabled" class="hidden">
                        <label for="commentabled">评论</label>
                    </div>
                </div>
            </div>

            <div class="ui error message"></div>
            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button type="button" id="save-btn" class="ui secondary button">保存</button>
                <button type="button" id="publish-btn" class="ui teal button">发布</button>
            </div>
        </form>
    </div>
</div>

<!--尾部-->
<footer th:replace="admin/_fragments :: footer">
</footer>

<!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script src="../../static/lib/editormd/editormd.min.js"></script>
<!--/*/</th:block>/*/-->

<script>

    $('.menu.toggle').click(
        function () {
            $('.m-item').toggleClass('m-mobile-hide');
        }
    )
    $('.ui.dropdown').dropdown({
        on: 'click'
    })
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'title',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请输入标题'
                }
                ]
            },
            content: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入内容'
                }
                ]
            },
            type: {
                identifier: 'type',
                rules: [{
                    type: 'empty',
                    prompt: '分类：请输入分类'
                }
                ]
            },
            firstPicture: {
                identifier: 'firstPicture',
                rules: [{
                    type: 'empty',
                    prompt: '首图：请写入首图'
                }
                ]
            },
            description: {
                identifier: 'description',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请写入博客描述'
                }
                ]
            }
        }
    })
    var testEditor;

    $("#save-btn").click(function () {
        $("[name = 'published']").val(false)
        $("#blog-form").submit();
    })
    $("#publish-btn").click(function () {
        $("[name = 'published']").val(true);
        $("#blog-form").submit();
    })


    $(function() {
        testEditor = editormd("md-content", {
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
            /*相对路径最后要加个斜杠*/
            path    : "/lib/editormd/lib/"
        });
    });
</script>
</body>
</html>